package com.wl4837.demo1;

// 代理类
class Proxy implements Subject {

    private RealSubject realSubject;

    @Override
    public void request() {
        if (realSubject == null) {
            realSubject = new RealSubject(); // 懒加载
        }
        preRequest(); // 访问前扩展
        realSubject.request();
        postRequest(); // 访问后扩展
    }

    private void preRequest() {
        System.out.println("Proxy: Preparing request.");
    }

    private void postRequest() {
        System.out.println("Proxy: Cleaning up after request.");
    }

}
